<!-- 跟进记录 --> 
<template>
  <div class="studentFollowManage">
    <el-card>
      <div class="opt_wrap">
        <div class="opt_wrap_left">
          <p>已选中<span style="color: #1796EB">{{ selectedNum }}</span>项</p>
          <p v-if="showBtn" @click="showDelModal = true">
            <i class="iconfont icon-shanchu1"></i>
            删除
          </p>
        </div>
      </div>
      <!-- <statisticsTag v-if="statisticsTagData" :data="statisticsTagData" @searchStatus="searchStatus"/> -->
      <div class="search_wrap">
        <el-input placeholder="学员名称/合同编号/学员手机号/负责人" v-model="searchCondition" clearable style="width: 260px;" @keyup.enter.native="queryListData">
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>
        <el-date-picker
          v-model="queryDate"
          @change="queryListData"
          type="daterange"
          range-separator="~"
          start-placeholder="提交起始日期"
          end-placeholder="提交结束日期">
        </el-date-picker>
        <!-- <el-select v-model="status" placeholder="合同状态" @change="queryListData" filterable clearable>
          <el-option v-for="item in statisticsTagData" :key="item.index" :label="item.label" :value="item.status">
            {{ item.label }}
          </el-option>
        </el-select> -->
      </div>
      <div class="table_list">
        <el-table
          ref="nicheTable"
          :data="tableListData"
          min-height="500"
          border
          v-loading="loading"
          @selection-change="handleSelectionNiche"
          style="width: 100%">
          <el-table-column type="selection" align="center" width="40"/>
          <el-table-column
            v-for="(item,index) in tableCaption"
            :key="index"
            :label="item.label"
            align="center">
            <template slot-scope="scope">
              <span>{{ scope.row[item.value] }}</span>
              <!-- <span v-if="item.value === 'name'" @click="goToURL('appointDetail', {type: 'see'})" class="see_detail">{{ scope.row[item.value] }}</span> -->
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <a class="operation" @click="goToURL('studnetFollowDetails', {id: scope.row.id})">查看</a>
            </template>
          </el-table-column>
        </el-table>
        <link-pagination :total="total" :currentPage="currentPage" :limit="limit" v-if="total != 0" @pagination="getPaginationParams"></link-pagination>
      </div>
    </el-card>
    <!-- 删除弹框 -->
    <el-dialog
      title="提示"
      width="510px"
      :visible.sync="showDelModal"
      class="del_modal">
      <div class="content">
        <p><i class="iconfont icon-tishi"></i></p>
        <!-- <p v-if="selectionCustomer.length === 1">是否将客户<span>{{ selectionCustomer[0].name }}删除？</span></p>
        <p v-if="selectionCustomer.length > 1">是否将<span>{{ selectionCustomer[0].name }}、{{ selectionCustomer[1].name }}<span v-if="selectionCustomer.length > 2">等</span>{{ selectionCustomer.length }}位客户删除？</span></p> -->
        <p>删除成功之后，该操作将无法恢复</p>
      </div>
      <div class="btn">
        <el-button @click="showDelModal = false">返回</el-button>
        <el-button type="primary" @click="confirmDelete">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import statisticsTag from '@/components/statisticsTag'
import { paginationMixin } from '@/mixin';
import http from '@/api/student_follow'
import {formatDate,formatArray} from '@/utils'
export default {
  name: 'studentFollowManage',
  mixins: [paginationMixin],
  components: {
    statisticsTag
  },
  data () {
    return {
      http: http,
      selectedNum: 0,
      showBtn: false,
      showDelModal: false,
      searchCondition: null,
      queryDate: null,
      step: null,
      steps: null,
      type: null,
      types: null,
      loading: false,
      total: 1,
      tableCaption: [
        {
          label: '姓名',
          value: 'name'
        },
        {
          label: '跟进编号',
          value: 'sno'
        },
        {
          label: '跟进方式',
          value: 'way'
        },
        {
          label: '跟进主题',
          value: 'title'
        },
        {
          label: '创建时间',
          value: 'create_time'
        },
        {
          label: '下次跟进时间',
          value: 'next_time'
        },
        {
          label: '操作人',
          value: 'username'
        }
      ],
      tableListData: [],
      contractChangeStatusList: [],
      // statisticsTagData: [],
      status: null,
      contractStatusList: [],
      auditStatusList: [],
      examineModal: false,
      infoTittle: null,
      infoDetail: [],
      examineForm: {},
      examineRules: {},
      infoRemark: '',
      detailInfo: null,
      delNiche: null
    }
  },
  methods: {
    confirmDelete () {
        let id = this.delNiche
        http.deleteContent({id}).then(res => {
            this.$message.success(res.msg || '删除成功')
            this.showDelModal = false
            this.getListData()
        })
    },
    goToURL (name, params) {
      this.$router.push({name, params})
    },
    examine(id) {
      http.getContentDetail({id}).then(res => {
        this.infoRemark = res.data.remark
        this.detailInfo = res.data
        let info = res.data
        let infoTittle = info.varname
        let infoContent = JSON.parse(info.varinfo)
        let infoContents = Object.keys(infoContent)
        let allInfo = []
        if (infoContents.length) {
          for (let info of infoContents) {
            allInfo.push({value: infoContent[info], label: info})
          }
        }
        for (let type of this.contractChangeStatusList) {
          if (type.value === infoTittle) {
            this.infoTittle = type.label
          }
        }
        this.infoDetail = allInfo
        console.log(this.infoDetail)
      })
      this.examineModal = true
    },
    searchStatus(status){
      this.status = status
      this.getListData()
    },
    goToURL (name, query) {
      this.$router.push({name, query})
    },
    queryListData () {
      this.getListData()
    },
    getListData(page=this.currentPage,list_rows=this.limit,search=this.searchCondition,status=this.status){
      this.loading = true;
      let params = {page,list_rows,search,status}
      if(this.queryDate){
        params['create_time_start'] = formatDate.toStr(new Date(this.queryDate[0]),'YYYY-MM-DD');
        params['create_time_end'] = formatDate.toStr(new Date(this.queryDate[1]),'YYYY-MM-DD');
      }
      let basicConfig = JSON.parse(sessionStorage.getItem('basicConfig'))
      this.nicheStatus = formatArray(basicConfig.opport_status)
      console.log(basicConfig)
      http.getList(params).then(res => {
        this.loading = false;
        this.total = res.data.total;
        let tableListData = res.data.data;
        if(tableListData.length){
          tableListData.map(item=>{
            for (let niche of this.nicheStatus) {
              if (item.opport_status === niche.label.status) {
                item.opport_status = niche.label.label
              }
            }
            for (let status of this.auditStatusList) {
              if (item.status - status.status === 0) {
                console.log(status)
                item.status = status.label
              }
            }
          })
        }
        this.tableListData = tableListData;
        for (let row of this.tableListData) {
          for (let status of this.contractChangeStatusList) {
            if (row.varname === status.value) {
              row.varname = status.label
            }
          }
        }
      })
    },
    handleSelectionNiche (val) {
      console.log(val)
      this.selectionCustomer = val
      this.selectedNum = this.selectionCustomer.length
      if (this.selectedNum === 0) {
        this.showBtn = false
      } else {
        this.showBtn = true
      }
      if (this.selectionCustomer.length !== 0) {
          this.delNiche = []
          for (let item of this.selectionCustomer) {
          this.delNiche.push(item.id)
          }
      }
    },
    confirmArrive () {
      let params = {
        id: this.detailInfo.id,
        status: this.examineForm.status,
        audit_msg: this.examineForm.audit_msg
      }
      http.auditContent(params).then(res => {
        this.$message.success(res.msg || '合同修改审核成功！')
        this.getListData()
        this.examineModal = false
      })
    },
    init(){
      this.getListData()
      let basicConfig = JSON.parse(sessionStorage.getItem('basicConfig'));
      let contractChangeStatusList = [];
      let keysData = Object.keys(basicConfig.audit_varname);
      if(keysData.length){
        keysData.map(item => {
            contractChangeStatusList.push({value: item,label: basicConfig.audit_varname[item]})
        })
        this.contractChangeStatusList = contractChangeStatusList;
      }
      let contractStatusList = []
      let keysData1 = Object.keys(basicConfig.contract_status);
      if(keysData1.length){
        keysData1.map(item => {
          contractStatusList.push({value: item,label: basicConfig.contract_status[item].a})
        })
        this.contractStatusList = contractStatusList;
      }
      this.auditStatusList = basicConfig.audit_status

      this.levelList = formatArray(basicConfig.user_level);
      console.log(this.levelList)
    }
  },
  created () {
    this.init()
    // http.getExamineStatus().then(res => {
    //   this.statisticsTagData = res.data
    // })
  }
}
</script>
<style lang="scss" scoped>
  .studentFollowManage {
    padding: 10px;
    .opt_wrap {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 34px;
      &_left {
        display: flex;
        p {
          margin-right: 18px;
          color: #565656;
          font-size: 16px;
          cursor: pointer;
          &:hover {
            color: #1796EB;
          }
          &:nth-of-type(1) {
            cursor: default;
            color: #646464;
            &:hover {
                color: #646464;
            }
          }
        }
      }
      &_right {
        display: flex;
        align-items: center;
        p {
          margin-left: 18px;
          color: #565656;
          font-size: 16px;
          cursor: pointer;
          &:hover {
            color: #1796EB;
          }
        }
        .add {
          width: 72px;
          height: 30px;
          background: linear-gradient(top left, #17B5EB, #1796EB);
          display: flex;
          justify-content: center;
          align-items: center;
          color: white;
          cursor: pointer;
          border-radius: 5px;
          &:hover {
            color: white;
          }
        }
      }
    }
    .search_wrap {
      margin-top: 34px;
      margin-bottom: 34px;
      div {
        margin-right: 17px;
      }
    }
    .see_detail {
      cursor: pointer;
      color: #1796EB;
    }
    .btn {
      margin-top: 30px;
      width: 100%;
      display: flex;
      justify-content: center;
      /deep/ .el-button {
        width: 214px;
      }
    }
    .del_modal {
      .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        p {
          &:nth-of-type(1) {
            width: 92px;
            height: 92px;
            border-radius: 50%;
            background: linear-gradient(to bottom, #F25851, #F27350);
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 18px;
            i {
              font-size: 40px;
              color: white;
            }
          }
          &:nth-of-type(2) {
            font-size: 20px;
            color: #333;
          }
          &:nth-of-type(3) {
            font-size: 14px;
            color: #999;
            margin-top: 7px;
          }
        }
      }
    }
    .operation {
      cursor: pointer;
      color: rgb(47, 156, 235)
    }
  }
</style>